import { MailchimpIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'

export const MailchimpBlock: BlockConfig = {
  type: 'mailchimp',
  name: 'Mailchimp',
  description: 'Manage audiences, campaigns, and marketing automation in Mailchimp',
  longDescription:
    'Integrate Mailchimp into the workflow. Can manage audiences (lists), list members, campaigns, automation workflows, templates, reports, segments, tags, merge fields, interest categories, landing pages, signup forms, and batch operations.',
  docsLink: 'https://docs.sim.ai/tools/mailchimp',
  authMode: AuthMode.ApiKey,
  category: 'tools',
  bgColor: '#FFE01B',
  icon: MailchimpIcon,
  subBlocks: [
    {
      id: 'operation',
      title: 'Operation',
      type: 'dropdown',
      options: [
        // Audience/List operations
        { label: 'Get Audiences', id: 'get_audiences' },
        { label: 'Get Audience', id: 'get_audience' },
        { label: 'Create Audience', id: 'create_audience' },
        { label: 'Update Audience', id: 'update_audience' },
        { label: 'Delete Audience', id: 'delete_audience' },
        // Member operations
        { label: 'Get Members', id: 'get_members' },
        { label: 'Get Member', id: 'get_member' },
        { label: 'Add Member', id: 'add_member' },
        { label: 'Add or Update Member', id: 'add_or_update_member' },
        { label: 'Update Member', id: 'update_member' },
        { label: 'Delete Member', id: 'delete_member' },
        { label: 'Archive Member', id: 'archive_member' },
        { label: 'Unarchive Member', id: 'unarchive_member' },
        // Campaign operations
        { label: 'Get Campaigns', id: 'get_campaigns' },
        { label: 'Get Campaign', id: 'get_campaign' },
        { label: 'Create Campaign', id: 'create_campaign' },
        { label: 'Update Campaign', id: 'update_campaign' },
        { label: 'Delete Campaign', id: 'delete_campaign' },
        { label: 'Send Campaign', id: 'send_campaign' },
        { label: 'Schedule Campaign', id: 'schedule_campaign' },
        { label: 'Unschedule Campaign', id: 'unschedule_campaign' },
        { label: 'Replicate Campaign', id: 'replicate_campaign' },
        // Campaign content operations
        { label: 'Get Campaign Content', id: 'get_campaign_content' },
        { label: 'Set Campaign Content', id: 'set_campaign_content' },
        // Automation operations
        { label: 'Get Automations', id: 'get_automations' },
        { label: 'Get Automation', id: 'get_automation' },
        { label: 'Start Automation', id: 'start_automation' },
        { label: 'Pause Automation', id: 'pause_automation' },
        { label: 'Add Subscriber to Automation', id: 'add_subscriber_to_automation' },
        // Template operations
        { label: 'Get Templates', id: 'get_templates' },
        { label: 'Get Template', id: 'get_template' },
        { label: 'Create Template', id: 'create_template' },
        { label: 'Update Template', id: 'update_template' },
        { label: 'Delete Template', id: 'delete_template' },
        // Report operations
        { label: 'Get Campaign Reports', id: 'get_campaign_reports' },
        { label: 'Get Campaign Report', id: 'get_campaign_report' },
        // Segment operations
        { label: 'Get Segments', id: 'get_segments' },
        { label: 'Get Segment', id: 'get_segment' },
        { label: 'Create Segment', id: 'create_segment' },
        { label: 'Update Segment', id: 'update_segment' },
        { label: 'Delete Segment', id: 'delete_segment' },
        { label: 'Get Segment Members', id: 'get_segment_members' },
        { label: 'Add Segment Member', id: 'add_segment_member' },
        { label: 'Remove Segment Member', id: 'remove_segment_member' },
        // Tag operations
        { label: 'Get Member Tags', id: 'get_member_tags' },
        { label: 'Add Member Tags', id: 'add_member_tags' },
        { label: 'Remove Member Tags', id: 'remove_member_tags' },
        // Merge fields operations
        { label: 'Get Merge Fields', id: 'get_merge_fields' },
        { label: 'Get Merge Field', id: 'get_merge_field' },
        { label: 'Create Merge Field', id: 'create_merge_field' },
        { label: 'Update Merge Field', id: 'update_merge_field' },
        { label: 'Delete Merge Field', id: 'delete_merge_field' },
        // Interest categories operations
        { label: 'Get Interest Categories', id: 'get_interest_categories' },
        { label: 'Get Interest Category', id: 'get_interest_category' },
        { label: 'Create Interest Category', id: 'create_interest_category' },
        { label: 'Update Interest Category', id: 'update_interest_category' },
        { label: 'Delete Interest Category', id: 'delete_interest_category' },
        // Interest operations
        { label: 'Get Interests', id: 'get_interests' },
        { label: 'Get Interest', id: 'get_interest' },
        { label: 'Create Interest', id: 'create_interest' },
        { label: 'Update Interest', id: 'update_interest' },
        { label: 'Delete Interest', id: 'delete_interest' },
        // Landing page operations
        { label: 'Get Landing Pages', id: 'get_landing_pages' },
        { label: 'Get Landing Page', id: 'get_landing_page' },
        { label: 'Create Landing Page', id: 'create_landing_page' },
        { label: 'Update Landing Page', id: 'update_landing_page' },
        { label: 'Delete Landing Page', id: 'delete_landing_page' },
        { label: 'Publish Landing Page', id: 'publish_landing_page' },
        { label: 'Unpublish Landing Page', id: 'unpublish_landing_page' },
        // Batch operations
        { label: 'Get Batch Operations', id: 'get_batch_operations' },
        { label: 'Get Batch Operation', id: 'get_batch_operation' },
        { label: 'Create Batch Operation', id: 'create_batch_operation' },
        { label: 'Delete Batch Operation', id: 'delete_batch_operation' },
      ],
      value: () => 'get_audiences',
    },
    {
      id: 'apiKey',
      title: 'API Key',
      type: 'short-input',
      password: true,
      placeholder: 'Enter your Mailchimp API key (includes server prefix)',
      required: true,
    },
    // Audience/List fields
    {
      id: 'listId',
      title: 'Audience ID',
      type: 'short-input',
      placeholder: 'Audience/List ID',
      required: {
        field: 'operation',
        value: [
          'get_audience',
          'update_audience',
          'delete_audience',
          'get_members',
          'get_member',
          'add_member',
          'add_or_update_member',
          'update_member',
          'delete_member',
          'archive_member',
          'unarchive_member',
          'get_segments',
          'get_segment',
          'create_segment',
          'update_segment',
          'delete_segment',
          'get_segment_members',
          'add_segment_member',
          'remove_segment_member',
          'get_member_tags',
          'add_member_tags',
          'remove_member_tags',
          'get_merge_fields',
          'get_merge_field',
          'create_merge_field',
          'update_merge_field',
          'delete_merge_field',
          'get_interest_categories',
          'get_interest_category',
          'create_interest_category',
          'update_interest_category',
          'delete_interest_category',
          'get_interests',
          'get_interest',
          'create_interest',
          'update_interest',
          'delete_interest',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_audience',
          'update_audience',
          'delete_audience',
          'get_members',
          'get_member',
          'add_member',
          'add_or_update_member',
          'update_member',
          'delete_member',
          'archive_member',
          'unarchive_member',
          'get_segments',
          'get_segment',
          'create_segment',
          'update_segment',
          'delete_segment',
          'get_segment_members',
          'add_segment_member',
          'remove_segment_member',
          'get_member_tags',
          'add_member_tags',
          'remove_member_tags',
          'get_merge_fields',
          'get_merge_field',
          'create_merge_field',
          'update_merge_field',
          'delete_merge_field',
          'get_interest_categories',
          'get_interest_category',
          'create_interest_category',
          'update_interest_category',
          'delete_interest_category',
          'get_interests',
          'get_interest',
          'create_interest',
          'update_interest',
          'delete_interest',
        ],
      },
    },
    {
      id: 'audienceName',
      title: 'Audience Name',
      type: 'short-input',
      placeholder: 'Name for the audience',
      required: {
        field: 'operation',
        value: ['create_audience'],
      },
      condition: {
        field: 'operation',
        value: ['create_audience', 'update_audience'],
      },
    },
    {
      id: 'contact',
      title: 'Contact Information',
      type: 'long-input',
      placeholder: 'JSON object with company, address1, city, state, zip, country',
      required: {
        field: 'operation',
        value: ['create_audience'],
      },
      condition: {
        field: 'operation',
        value: ['create_audience', 'update_audience'],
      },
    },
    {
      id: 'permissionReminder',
      title: 'Permission Reminder',
      type: 'short-input',
      placeholder: 'Permission reminder text',
      required: {
        field: 'operation',
        value: ['create_audience'],
      },
      condition: {
        field: 'operation',
        value: ['create_audience', 'update_audience'],
      },
    },
    {
      id: 'campaignDefaults',
      title: 'Campaign Defaults',
      type: 'long-input',
      placeholder: 'JSON object with from_name, from_email, subject, language',
      required: {
        field: 'operation',
        value: ['create_audience'],
      },
      condition: {
        field: 'operation',
        value: ['create_audience', 'update_audience'],
      },
    },
    {
      id: 'emailTypeOption',
      title: 'Email Type Option',
      type: 'dropdown',
      options: [
        { label: 'True', id: 'true' },
        { label: 'False', id: 'false' },
      ],
      required: {
        field: 'operation',
        value: ['create_audience'],
      },
      condition: {
        field: 'operation',
        value: ['create_audience', 'update_audience'],
      },
      value: () => 'true',
    },
    // Member fields
    {
      id: 'subscriberEmail',
      title: 'Subscriber Email',
      type: 'short-input',
      placeholder: 'Email address or MD5 hash',
      required: {
        field: 'operation',
        value: [
          'get_member',
          'update_member',
          'delete_member',
          'archive_member',
          'unarchive_member',
          'get_member_tags',
          'add_member_tags',
          'remove_member_tags',
          'add_or_update_member',
          'remove_segment_member',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_member',
          'update_member',
          'delete_member',
          'archive_member',
          'unarchive_member',
          'get_member_tags',
          'add_member_tags',
          'remove_member_tags',
          'add_or_update_member',
          'remove_segment_member',
        ],
      },
    },
    {
      id: 'emailAddress',
      title: 'Email Address',
      type: 'short-input',
      placeholder: 'Member email address',
      required: {
        field: 'operation',
        value: [
          'add_member',
          'add_or_update_member',
          'unarchive_member',
          'add_segment_member',
          'add_subscriber_to_automation',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'add_member',
          'add_or_update_member',
          'update_member',
          'unarchive_member',
          'add_segment_member',
          'add_subscriber_to_automation',
        ],
      },
    },
    {
      id: 'status',
      title: 'Status',
      type: 'dropdown',
      options: [
        { label: 'Subscribed', id: 'subscribed' },
        { label: 'Unsubscribed', id: 'unsubscribed' },
        { label: 'Cleaned', id: 'cleaned' },
        { label: 'Pending', id: 'pending' },
        { label: 'Transactional', id: 'transactional' },
      ],
      required: {
        field: 'operation',
        value: ['add_member', 'unarchive_member'],
      },
      condition: {
        field: 'operation',
        value: ['get_members', 'add_member', 'update_member', 'unarchive_member'],
      },
    },
    {
      id: 'statusIfNew',
      title: 'Status If New',
      type: 'dropdown',
      options: [
        { label: 'Subscribed', id: 'subscribed' },
        { label: 'Unsubscribed', id: 'unsubscribed' },
        { label: 'Cleaned', id: 'cleaned' },
        { label: 'Pending', id: 'pending' },
        { label: 'Transactional', id: 'transactional' },
      ],
      required: {
        field: 'operation',
        value: ['add_or_update_member'],
      },
      condition: {
        field: 'operation',
        value: ['add_or_update_member'],
      },
    },
    {
      id: 'mergeFields',
      title: 'Merge Fields',
      type: 'long-input',
      placeholder: 'JSON object with merge field values (e.g., {"FNAME": "John", "LNAME": "Doe"})',
      condition: {
        field: 'operation',
        value: ['add_member', 'add_or_update_member', 'update_member'],
      },
    },
    {
      id: 'interests',
      title: 'Interests',
      type: 'long-input',
      placeholder: 'JSON object with interest IDs and boolean values',
      condition: {
        field: 'operation',
        value: ['add_member', 'add_or_update_member', 'update_member'],
      },
    },
    {
      id: 'tags',
      title: 'Tags',
      type: 'long-input',
      placeholder: 'JSON array of tag objects with name and status',
      required: {
        field: 'operation',
        value: ['add_member_tags', 'remove_member_tags'],
      },
      condition: {
        field: 'operation',
        value: ['add_member_tags', 'remove_member_tags'],
      },
    },
    // Campaign fields
    {
      id: 'campaignId',
      title: 'Campaign ID',
      type: 'short-input',
      placeholder: 'Campaign ID',
      required: {
        field: 'operation',
        value: [
          'get_campaign',
          'update_campaign',
          'delete_campaign',
          'send_campaign',
          'schedule_campaign',
          'unschedule_campaign',
          'replicate_campaign',
          'get_campaign_content',
          'set_campaign_content',
          'get_campaign_report',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_campaign',
          'update_campaign',
          'delete_campaign',
          'send_campaign',
          'schedule_campaign',
          'unschedule_campaign',
          'replicate_campaign',
          'get_campaign_content',
          'set_campaign_content',
          'get_campaign_report',
        ],
      },
    },
    {
      id: 'campaignType',
      title: 'Campaign Type',
      type: 'dropdown',
      options: [
        { label: 'Regular', id: 'regular' },
        { label: 'Plain Text', id: 'plaintext' },
        { label: 'A/B Split', id: 'absplit' },
        { label: 'RSS', id: 'rss' },
        { label: 'Variate', id: 'variate' },
      ],
      required: {
        field: 'operation',
        value: ['create_campaign'],
      },
      condition: {
        field: 'operation',
        value: ['get_campaigns', 'create_campaign'],
      },
    },
    {
      id: 'campaignSettings',
      title: 'Campaign Settings',
      type: 'long-input',
      placeholder: 'JSON object with subject_line, from_name, reply_to, etc. (required for create)',
      required: {
        field: 'operation',
        value: ['create_campaign'],
      },
      condition: {
        field: 'operation',
        value: ['create_campaign', 'update_campaign'],
      },
    },
    {
      id: 'recipients',
      title: 'Recipients',
      type: 'long-input',
      placeholder: 'JSON object with list_id and optional segment_opts',
      condition: {
        field: 'operation',
        value: ['create_campaign', 'update_campaign'],
      },
    },
    {
      id: 'scheduleTime',
      title: 'Schedule Time',
      type: 'short-input',
      placeholder: 'ISO 8601 date-time (e.g., 2024-12-31T10:00:00+00:00)',
      required: {
        field: 'operation',
        value: ['schedule_campaign'],
      },
      condition: {
        field: 'operation',
        value: ['schedule_campaign'],
      },
    },
    {
      id: 'html',
      title: 'HTML Content',
      type: 'long-input',
      placeholder: 'HTML content for the campaign',
      condition: {
        field: 'operation',
        value: ['set_campaign_content'],
      },
    },
    {
      id: 'plainText',
      title: 'Plain Text Content',
      type: 'long-input',
      placeholder: 'Plain text content for the campaign',
      condition: {
        field: 'operation',
        value: ['set_campaign_content'],
      },
    },
    {
      id: 'templateId',
      title: 'Template ID',
      type: 'short-input',
      placeholder: 'Template ID',
      required: {
        field: 'operation',
        value: ['get_template', 'update_template', 'delete_template'],
      },
      condition: {
        field: 'operation',
        value: ['get_template', 'update_template', 'delete_template', 'set_campaign_content'],
      },
    },
    {
      id: 'templateName',
      title: 'Template Name',
      type: 'short-input',
      placeholder: 'Template name',
      required: {
        field: 'operation',
        value: ['create_template'],
      },
      condition: {
        field: 'operation',
        value: ['create_template', 'update_template'],
      },
    },
    {
      id: 'templateHtml',
      title: 'Template HTML',
      type: 'long-input',
      placeholder: 'HTML content for the template',
      required: {
        field: 'operation',
        value: ['create_template'],
      },
      condition: {
        field: 'operation',
        value: ['create_template', 'update_template'],
      },
    },
    // Automation fields
    {
      id: 'workflowId',
      title: 'Workflow ID',
      type: 'short-input',
      placeholder: 'Automation workflow ID',
      required: {
        field: 'operation',
        value: [
          'get_automation',
          'start_automation',
          'pause_automation',
          'add_subscriber_to_automation',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_automation',
          'start_automation',
          'pause_automation',
          'add_subscriber_to_automation',
        ],
      },
    },
    {
      id: 'workflowEmailId',
      title: 'Workflow Email ID',
      type: 'short-input',
      placeholder: 'Workflow email ID',
      required: {
        field: 'operation',
        value: ['add_subscriber_to_automation'],
      },
      condition: {
        field: 'operation',
        value: ['add_subscriber_to_automation'],
      },
    },
    // Segment fields
    {
      id: 'segmentId',
      title: 'Segment ID',
      type: 'short-input',
      placeholder: 'Segment ID',
      required: {
        field: 'operation',
        value: [
          'get_segment',
          'update_segment',
          'delete_segment',
          'get_segment_members',
          'add_segment_member',
          'remove_segment_member',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_segment',
          'update_segment',
          'delete_segment',
          'get_segment_members',
          'add_segment_member',
          'remove_segment_member',
        ],
      },
    },
    {
      id: 'segmentName',
      title: 'Segment Name',
      type: 'short-input',
      placeholder: 'Segment name',
      required: {
        field: 'operation',
        value: ['create_segment'],
      },
      condition: {
        field: 'operation',
        value: ['create_segment', 'update_segment'],
      },
    },
    {
      id: 'segmentOptions',
      title: 'Segment Options',
      type: 'long-input',
      placeholder: 'JSON object with conditions for segment',
      condition: {
        field: 'operation',
        value: ['create_segment', 'update_segment'],
      },
    },
    // Merge field fields
    {
      id: 'mergeId',
      title: 'Merge Field ID',
      type: 'short-input',
      placeholder: 'Merge field ID',
      required: {
        field: 'operation',
        value: ['get_merge_field', 'update_merge_field', 'delete_merge_field'],
      },
      condition: {
        field: 'operation',
        value: ['get_merge_field', 'update_merge_field', 'delete_merge_field'],
      },
    },
    {
      id: 'mergeName',
      title: 'Merge Field Name',
      type: 'short-input',
      placeholder: 'Merge field name',
      required: {
        field: 'operation',
        value: ['create_merge_field'],
      },
      condition: {
        field: 'operation',
        value: ['create_merge_field', 'update_merge_field'],
      },
    },
    {
      id: 'mergeType',
      title: 'Merge Field Type',
      type: 'dropdown',
      options: [
        { label: 'Text', id: 'text' },
        { label: 'Number', id: 'number' },
        { label: 'Address', id: 'address' },
        { label: 'Phone', id: 'phone' },
        { label: 'Date', id: 'date' },
        { label: 'URL', id: 'url' },
        { label: 'Image URL', id: 'imageurl' },
        { label: 'Radio', id: 'radio' },
        { label: 'Dropdown', id: 'dropdown' },
        { label: 'Birthday', id: 'birthday' },
        { label: 'Zip', id: 'zip' },
      ],
      required: {
        field: 'operation',
        value: ['create_merge_field'],
      },
      condition: {
        field: 'operation',
        value: ['create_merge_field'],
      },
    },
    // Interest category fields
    {
      id: 'interestCategoryId',
      title: 'Interest Category ID',
      type: 'short-input',
      placeholder: 'Interest category ID',
      required: {
        field: 'operation',
        value: [
          'get_interest_category',
          'update_interest_category',
          'delete_interest_category',
          'get_interests',
          'get_interest',
          'create_interest',
          'update_interest',
          'delete_interest',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_interest_category',
          'update_interest_category',
          'delete_interest_category',
          'get_interests',
          'get_interest',
          'create_interest',
          'update_interest',
          'delete_interest',
        ],
      },
    },
    {
      id: 'interestCategoryTitle',
      title: 'Interest Category Title',
      type: 'short-input',
      placeholder: 'Interest category title',
      required: {
        field: 'operation',
        value: ['create_interest_category'],
      },
      condition: {
        field: 'operation',
        value: ['create_interest_category', 'update_interest_category'],
      },
    },
    {
      id: 'interestCategoryType',
      title: 'Interest Category Type',
      type: 'dropdown',
      options: [
        { label: 'Checkboxes', id: 'checkboxes' },
        { label: 'Dropdown', id: 'dropdown' },
        { label: 'Radio', id: 'radio' },
        { label: 'Hidden', id: 'hidden' },
      ],
      required: {
        field: 'operation',
        value: ['create_interest_category'],
      },
      condition: {
        field: 'operation',
        value: ['create_interest_category'],
      },
    },
    // Interest fields
    {
      id: 'interestId',
      title: 'Interest ID',
      type: 'short-input',
      placeholder: 'Interest ID',
      required: {
        field: 'operation',
        value: ['get_interest', 'update_interest', 'delete_interest'],
      },
      condition: {
        field: 'operation',
        value: ['get_interest', 'update_interest', 'delete_interest'],
      },
    },
    {
      id: 'interestName',
      title: 'Interest Name',
      type: 'short-input',
      placeholder: 'Interest name',
      required: {
        field: 'operation',
        value: ['create_interest'],
      },
      condition: {
        field: 'operation',
        value: ['create_interest', 'update_interest'],
      },
    },
    // Landing page fields
    {
      id: 'pageId',
      title: 'Landing Page ID',
      type: 'short-input',
      placeholder: 'Landing page ID',
      required: {
        field: 'operation',
        value: [
          'get_landing_page',
          'update_landing_page',
          'delete_landing_page',
          'publish_landing_page',
          'unpublish_landing_page',
        ],
      },
      condition: {
        field: 'operation',
        value: [
          'get_landing_page',
          'update_landing_page',
          'delete_landing_page',
          'publish_landing_page',
          'unpublish_landing_page',
        ],
      },
    },
    {
      id: 'landingPageTitle',
      title: 'Landing Page Title',
      type: 'short-input',
      placeholder: 'Landing page title',
      condition: {
        field: 'operation',
        value: ['create_landing_page', 'update_landing_page'],
      },
    },
    {
      id: 'landingPageType',
      title: 'Landing Page Type',
      type: 'dropdown',
      options: [
        { label: 'Signup', id: 'signup' },
        { label: 'Click Through', id: 'click-through' },
      ],
      required: {
        field: 'operation',
        value: ['create_landing_page'],
      },
      condition: {
        field: 'operation',
        value: ['create_landing_page'],
      },
    },
    // Batch operation fields
    {
      id: 'batchId',
      title: 'Batch ID',
      type: 'short-input',
      placeholder: 'Batch operation ID',
      required: {
        field: 'operation',
        value: ['get_batch_operation', 'delete_batch_operation'],
      },
      condition: {
        field: 'operation',
        value: ['get_batch_operation', 'delete_batch_operation'],
      },
    },
    {
      id: 'operations',
      title: 'Operations',
      type: 'long-input',
      placeholder: 'JSON array of operations with method, path, body, etc.',
      required: {
        field: 'operation',
        value: ['create_batch_operation'],
      },
      condition: {
        field: 'operation',
        value: ['create_batch_operation'],
      },
    },
    // Pagination and filtering
    {
      id: 'count',
      title: 'Count',
      type: 'short-input',
      placeholder: 'Number of results (default: 10, max: 1000)',
      condition: {
        field: 'operation',
        value: [
          'get_audiences',
          'get_members',
          'get_campaigns',
          'get_automations',
          'get_templates',
          'get_campaign_reports',
          'get_segments',
          'get_segment_members',
          'get_merge_fields',
          'get_interest_categories',
          'get_interests',
          'get_landing_pages',
          'get_batch_operations',
        ],
      },
    },
    {
      id: 'offset',
      title: 'Offset',
      type: 'short-input',
      placeholder: 'Number of results to skip',
      condition: {
        field: 'operation',
        value: [
          'get_audiences',
          'get_members',
          'get_campaigns',
          'get_automations',
          'get_templates',
          'get_campaign_reports',
          'get_segments',
          'get_segment_members',
          'get_merge_fields',
          'get_interest_categories',
          'get_interests',
          'get_landing_pages',
          'get_batch_operations',
        ],
      },
    },
  ],
  tools: {
    access: [
      'mailchimp_get_audiences',
      'mailchimp_get_audience',
      'mailchimp_create_audience',
      'mailchimp_update_audience',
      'mailchimp_delete_audience',
      'mailchimp_get_members',
      'mailchimp_get_member',
      'mailchimp_add_member',
      'mailchimp_add_or_update_member',
      'mailchimp_update_member',
      'mailchimp_delete_member',
      'mailchimp_archive_member',
      'mailchimp_unarchive_member',
      'mailchimp_get_campaigns',
      'mailchimp_get_campaign',
      'mailchimp_create_campaign',
      'mailchimp_update_campaign',
      'mailchimp_delete_campaign',
      'mailchimp_send_campaign',
      'mailchimp_schedule_campaign',
      'mailchimp_unschedule_campaign',
      'mailchimp_replicate_campaign',
      'mailchimp_get_campaign_content',
      'mailchimp_set_campaign_content',
      'mailchimp_get_automations',
      'mailchimp_get_automation',
      'mailchimp_start_automation',
      'mailchimp_pause_automation',
      'mailchimp_add_subscriber_to_automation',
      'mailchimp_get_templates',
      'mailchimp_get_template',
      'mailchimp_create_template',
      'mailchimp_update_template',
      'mailchimp_delete_template',
      'mailchimp_get_campaign_reports',
      'mailchimp_get_campaign_report',
      'mailchimp_get_segments',
      'mailchimp_get_segment',
      'mailchimp_create_segment',
      'mailchimp_update_segment',
      'mailchimp_delete_segment',
      'mailchimp_get_segment_members',
      'mailchimp_add_segment_member',
      'mailchimp_remove_segment_member',
      'mailchimp_get_member_tags',
      'mailchimp_add_member_tags',
      'mailchimp_remove_member_tags',
      'mailchimp_get_merge_fields',
      'mailchimp_get_merge_field',
      'mailchimp_create_merge_field',
      'mailchimp_update_merge_field',
      'mailchimp_delete_merge_field',
      'mailchimp_get_interest_categories',
      'mailchimp_get_interest_category',
      'mailchimp_create_interest_category',
      'mailchimp_update_interest_category',
      'mailchimp_delete_interest_category',
      'mailchimp_get_interests',
      'mailchimp_get_interest',
      'mailchimp_create_interest',
      'mailchimp_update_interest',
      'mailchimp_delete_interest',
      'mailchimp_get_landing_pages',
      'mailchimp_get_landing_page',
      'mailchimp_create_landing_page',
      'mailchimp_update_landing_page',
      'mailchimp_delete_landing_page',
      'mailchimp_publish_landing_page',
      'mailchimp_unpublish_landing_page',
      'mailchimp_get_batch_operations',
      'mailchimp_get_batch_operation',
      'mailchimp_create_batch_operation',
      'mailchimp_delete_batch_operation',
    ],
    config: {
      tool: (params) => {
        return `mailchimp_${params.operation}`
      },
      params: (params) => {
        const { apiKey, operation, ...rest } = params
        const cleanParams: Record<string, any> = { apiKey }

        Object.entries(rest).forEach(([key, value]) => {
          if (value !== undefined && value !== null && value !== '') {
            cleanParams[key] = value
          }
        })
        return cleanParams
      },
    },
  },
  inputs: {
    operation: { type: 'string', description: 'Operation to perform' },
    apiKey: { type: 'string', description: 'Mailchimp API key with server prefix' },
  },
  outputs: {
    success: { type: 'boolean', description: 'Operation success status' },
    output: { type: 'json', description: 'Operation result data' },
  },
}
